package org.pearl.oauth2.resourceserver001demo.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by TD on 2021/7/16
 * http://localhost:9001/resource
 */
@RequestMapping
@RestController
public class ResourceController {


    @GetMapping("/resource")
   //@PreAuthorize("hasAuthority('role')") // 用户信息中的权限
    public String resource(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication.toString());
        return "访问到了resource 资源 ";
    }
}
